<template>
    <div>
        <div class="mui-numbox" data-numbox-min='1'>
            <button class="mui-btn mui-btn-numbox-minus" type="button">-</button>
            <input @change="countChanged" ref="numbox" id="test" class="mui-input-numbox" type="number"
                   :value="initcount" />
            <button class="mui-btn mui-btn-numbox-plus" type="button">+</button>
        </div>
    </div>
</template>
<script>
    import mui from '../../lib/mui/js/mui.js'
    export default{
        data(){
            return {}
        },
        created(){
        },
        mounted(){
            //初始化数字选择框组件
            mui('.mui-numbox').numbox();
        },
        methods: {
            //改变商品数量
            //每当数量值改变，就立即把最新值同
            // 步到购物车store中，覆盖之前的数量值
            countChanged(){
                this.$store.commit('updateGoodsInfo',{
                    id:this.goodsid,
                    count:this.$refs.numbox.value
                })
            },
        },
        props:['initcount','goodsid'],
        computed: {},
        components: {}
    }
</script>
<style lang="scss" scoped>
    .mui-numbox{
        height: 25px;
        width: 72px;
        padding: 0 20px;
        .mui-btn{
            width: 20px;
        }
        .mui-input-numbox{
            width: 30px!important;
        }
    }

</style>